package io.gitee.yth.design.pattern.test.core.pattern.behavioral.state;

/**
 * @author yth
 * @since 2023-05-03-0:27
 */
public class TCPEstablished extends AbstractTCPState {

    private static final TCPEstablished instance = new TCPEstablished();

    public static TCPEstablished getInstance() {
        return instance;
    }

    private TCPEstablished() {
    }

    @Override
    public void transmit(TCPConnection tcpConnection, TCPOctetStream tcpOctetStream) {
        System.out.println("transmit ...");
        tcpConnection.processOctet(tcpOctetStream);
    }

    @Override
    public void close(TCPConnection tcpConnection) {
        System.out.println("close ...");
        // send FIN, receive ACK of FIN
        changeState(tcpConnection, TCPListen.getInstance());
    }
}
